﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................


namespace QLKTX1._0.DAO
{
    class NguoiDungDAO
    {
        public static List<NguoiDungDTO> dsNguoiDung()
        {
            List<NguoiDungDTO> dsNguoiDung = new List<NguoiDungDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM nguoiDung order by (tenDangNhap) asc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NguoiDungDTO nd = new NguoiDungDTO();

                nd.MaDangNhap = dt.Rows[i]["maDangNhap"].ToString();
                nd.MatKhau = dt.Rows[i]["matKhau"].ToString();

                dsNguoiDung.Add(nd);
                
            }
            return dsNguoiDung;
        }

        //ham them 
        public static bool themNguoiDung(NguoiDungDTO nd)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO nguoiDung(maDangNhap,matKhau) VALUES('"+ nd.MaDangNhap +"','" + nd.MatKhau  + "')");
        }
        //ham xoa 
        public static bool xoaNguoiDung(NguoiDungDTO nd)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM nguoiDung WHERE maDangNhap='" + nd.MaDangNhap + "' ");
        }
        //ham cap nhat 
        public static bool capNhatNguoiDung(NguoiDungDTO nd)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE nguoiDung set maDangNhap='" + nd.MaDangNhap + "','" + nd.MatKhau + "' WHERE maDangNhap='" + nd.MaDangNhap + "' ");
        }
    }
}
